package socket;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class ReceiveDemo {
    public static void main(String[] args) throws IOException {
        //1.创建服务端对象
        ServerSocket ss = new ServerSocket(1002);
        //2.监听客户端的链接
        Socket socket = ss.accept();
        //3.创建流读取数据
        InputStream os = socket.getInputStream();
        InputStreamReader isr = new InputStreamReader(os);
        //4.解析数据并打印
        int b;
        while((b = isr.read()) != -1){
            System.out.print((char)b);
        }
        //5.释放资源
        os.close();
        ss.close();
    }
}
